Skip to content

feat(dtls): add a config option for server-side SRTP protection profile preference - #337

Open
kuzmig wants to merge 1 commit into
webrtc-rs:masterfrom
kuzmig:feat/server-srtp-profile-preference
Open

kuzmig wants to merge 1 commit into
webrtc-rs:masterfrom
kuzmig:feat/server-srtp-profile-preference

Conversation

@kuzmig

@kuzmig kuzmig commented Nov 20, 2026

Copy link
Copy Markdown

Summary

Implementation of #335

Changes

  • config.rs: pub enum SrtpProfileSelection { ClientPreference (default), ServerPreference } + ConfigBuilder::with_srtp_profile_selection(), plumbed through build() into HandshakeConfig.
  • lib.rs: select_srtp_profile(selection, client_offer, local) — the single place that decides the iteration order; unit tests pin the policy matrix (client order, server order, server order within the client's offer — the RFC boundary — and no intersection → error).
  • flight0.rs / flight3.rs: both server-side call sites routed through select_srtp_profile.
  • conn/mod.rs + endpoint.rs: DTLSConn::selected_srtp_protection_profile is now pub (pion parity: Connection.SelectedSRTPProtectionProfile) and Endpoint::connection(&remote) exposes the established connection, so integrators can inspect the negotiated profile.
  • tests/srtp_profile_selection.rs: integration tests over real handshakes — client [SHA1_80, SHA1_32] vs server [SHA1_32, SHA1_80] (orders deliberately conflict): ClientPreference selects SHA1_80, ServerPreference selects SHA1_32, on both sides.

Testing

  • cargo test -p rtc-dtls — 84 tests green (unit + integration, incl. the two new handshake-level tests).
  • cargo clippy -p rtc-dtls clean, cargo fmt applied.

flight0/flight3 select the SRTP protection profile by iterating the
client's use_srtp offer first; Config::local_srtp_protection_profiles
acts only as a membership filter, so its order never affects the outcome.
Standard TLS practice is server preference (RFC 5246/8446), and RFC 5764
§4.1.1 mandates only that the server select a single profile the client
offered — the policy within the offered set is the server's.

Add ConfigBuilder::with_srtp_profile_selection
(SrtpProfileSelection::ClientPreference | ServerPreference; the default
keeps the historical client-order behavior) and route both server-side
call sites through select_srtp_profile. Expose
DTLSConn::selected_srtp_protection_profile publicly (pion parity:
Connection.SelectedSRTPProtectionProfile) and add
Endpoint::connection(&remote) so integrators can inspect the negotiated
profile; include integration tests pinning both policies over real
handshakes.

Without ServerPreference, gateways that must rank the intersection by
their own policy (AEAD when offered, legacy HMAC-SHA1 otherwise) have to
parse the client's ClientHello themselves before feeding it to the
engine, duplicating the use_srtp parsing the library already performs.
@kuzmig kuzmig changed the title feat(dtls): server-side SRTP protection profile preference option dtls: Add a config option for server-side SRTP protection profile preference Nov 20, 2026
@kuzmig kuzmig changed the title dtls: Add a config option for server-side SRTP protection profile preference feat(dtls): add a config option for server-side SRTP protection profile preference Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant